{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\m.comola\Dropbox\Nepal Banking Networks\drafts\REStat submission\5. accepted\data\dofile ComolaPrina.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}16 Jan 2020, 09:20:28

{com}. do "C:\Users\m.comola\Dropbox\Nepal Banking Networks\drafts\REStat submission\5. accepted\data\dofile ComolaPrina.do"
{txt}
{com}. 
. /* THIS DO-FILE WAS WRITTEN IN MAY 2019 BY MARGHERITA COMOLA,
> IT RUNS ALL RESULTS FOR THE EMPIRICAL ILLUSTRATION ON NEPALESE DATA
> (`Treatment Effects Accounting for Network Changes', Comola Prina, REStat) */
. 
. clear all
{txt}
{com}. set maxvar 30000

{txt}
{com}. set matsize 11000
{txt}
{com}. set more off
{txt}
{com}. 
. /*******************************************************************
> ********************************************************************
> *** COMPUTE AND SAVE THE INTERACTION MATRICES
> *******************************************************************
> ********************************************************************/
. 
. use dyadic_dataset_ComolaPrina.dta, clear
{txt}
{com}. 
. sort HHNO1 HHNO2
{txt}
{com}. fillin  HHNO1 HHNO2
{txt}
{com}. replace link_bin0=0 if link_bin0==.
{txt}(780,917 real changes made)

{com}. replace link_bin1=0 if link_bin1==.
{txt}(780,917 real changes made)

{com}. 
. mata 
{txt}{hline 49} mata (type {cmd:end} to exit) {hline}
{com}: 
: /* binary matrix */
: 
: G0 = st_data(., "link_bin0")
{res}
{com}: G0 = colshape(G0, 915) 
{res}
{com}: 
: G1 = st_data(., "link_bin1")
{res}
{com}: G1 = colshape(G1, 915) 
{res}
{com}: 
: /* semi row-standardization */
: 
: G0_S=rowsum(G0,.)
{res}
{com}: G0=G0:/G0_S
{res}
{com}: 
: G1_S=rowsum(G1,.)
{res}
{com}: G1=G1:/G1_S
{res}
{com}: 
: mata drop G0_S G1_S

: 
: /* missing values */
: 
: G0=editmissing(G0, 0)
{res}
{com}: G1=editmissing(G1, 0)
{res}
{com}: 
: /* delta_G */
: 
: deltaG=G1-G0
{res}
{com}: 
: st_matrix("G0", G0)
{res}
{com}: st_matrix("G1", G1)
{res}
{com}: 
: end
{txt}{hline}

{com}. 
. /* re-import into Stata */
. 
. clear
{txt}
{com}. svmat G0
{txt}number of observations will be reset to 915
Press any key to continue, or Break to abort
{p}
number of observations (_N)  was 0,
now 915
{p_end}

{com}. stack G01-G0915, into (link_s0)
{txt}Warning:  data in memory will be lost.
         Press any key to continue, Ctrl-Break to abort.

{com}. gen serial=_n
{txt}
{com}. sort serial 
{txt}
{com}. drop _stack
{txt}
{com}. save temp0.dta, replace 
{txt}(note: file temp0.dta not found)
file temp0.dta saved

{com}. 
. clear
{txt}
{com}. svmat G1
{txt}number of observations will be reset to 915
Press any key to continue, or Break to abort
{p}
number of observations (_N)  was 0,
now 915
{p_end}

{com}. stack G11-G1915, into (link_s1)
{txt}Warning:  data in memory will be lost.
         Press any key to continue, Ctrl-Break to abort.

{com}. gen serial=_n
{txt}
{com}. sort serial 
{txt}
{com}. drop _stack
{txt}
{com}. save temp1.dta, replace 
{txt}(note: file temp1.dta not found)
file temp1.dta saved

{com}. 
. /* merge into the dyadic data */
. 
. use dyadic_dataset_ComolaPrina.dta, clear
{txt}
{com}. 
. fillin HHNO1 HHNO2
{txt}
{com}. sort  HHNO1 HHNO2
{txt}
{com}. gen serial=_n
{txt}
{com}. 
. sort serial
{txt}
{com}. merge serial using temp0
{txt}{p}
(note: you are using old
{bf:merge} syntax; see
{bf:{help merge:[D] merge}} for new syntax)
{p_end}

{com}. drop _merge
{txt}
{com}. capture erase temp0.dta
{txt}
{com}. 
. sort serial
{txt}
{com}. merge serial using temp1
{txt}{p}
(note: you are using old
{bf:merge} syntax; see
{bf:{help merge:[D] merge}} for new syntax)
{p_end}

{com}. drop _merge
{txt}
{com}. capture erase temp1.dta
{txt}
{com}. 
. keep if _fillin==0
{txt}(780,002 observations deleted)

{com}. drop _fillin serial
{txt}
{com}. replace link_s0=. if HHNO1==HHNO2
{txt}(915 real changes made, 915 to missing)

{com}. replace link_s1=. if HHNO1==HHNO2
{txt}(915 real changes made, 915 to missing)

{com}. 
. /*******************************************************************
> ********************************************************************
> *** DYADIC ANALYSIS
> *******************************************************************
> ********************************************************************/
. 
. /* des stats*/
. 
. gen some_treated=(ITT_H11==1 | ITT_H21==1)
{txt}
{com}. gen both_treated=(ITT_H11==1 & ITT_H21==1)
{txt}
{com}. gen one_treated=((ITT_H11==1 & ITT_H21==0) | (ITT_H11==0 & ITT_H21==1))
{txt}
{com}. 
. tabstat link_bin0 link_s0 both_married0 abs_diff_chl160 abs_diff_HHmembers0 some_shock_livestock0 some_shock_death0 if HHNO1!=HHNO2, stats (count mean min max sd) columns(statistics) longstub varwidth(30) labelwidth(30)

{txt}{ralign 30:variable} {...}
{c |}         N      mean       min       max        sd
{hline 31}{c +}{hline 50}
{ralign 30:link_bin0} {...}
{c |}{...}
 {res}    56308  .0116502         0         1  .1073065
{txt}{ralign 30:link_s0} {...}
{c |}{...}
 {res}    56308   .007086         0         1  .0737662
{txt}{ralign 30:both_married0} {...}
{c |}{...}
 {res}    56308   .786105         0         1  .4100572
{txt}{ralign 30:abs_diff_chl160} {...}
{c |}{...}
 {res}    56308  1.407544         0         7  1.182569
{txt}{ralign 30:abs_diff_HHmembers0} {...}
{c |}{...}
 {res}    56308  1.802799         0        11  1.526707
{txt}{ralign 30:some_shock_livestock0} {...}
{c |}{...}
 {res}    56308  .1504227         0         1  .3574884
{txt}{ralign 30:some_shock_death0} {...}
{c |}{...}
 {res}    56308  .0230518         0         1  .1500693
{txt}{hline 31}{c BT}{hline 50}

{com}. tabstat link_bin1 link_s1 both_married1 abs_diff_chl161 abs_diff_HHmembers1 some_shock_livestock1 some_shock_death1 some_treated both_treated one_treated if HHNO1!=HHNO2, stats (count mean min max sd) columns(statistics) longstub varwidth(30) labelwidth(30)

{txt}{ralign 30:variable} {...}
{c |}         N      mean       min       max        sd
{hline 31}{c +}{hline 50}
{ralign 30:link_bin1} {...}
{c |}{...}
 {res}    56308  .0116857         0         1   .107468
{txt}{ralign 30:link_s1} {...}
{c |}{...}
 {res}    56308  .0077609         0         1  .0793281
{txt}{ralign 30:both_married1} {...}
{c |}{...}
 {res}    56308  .7294878         0         1  .4442284
{txt}{ralign 30:abs_diff_chl161} {...}
{c |}{...}
 {res}    56308  1.294878         0         6  1.057293
{txt}{ralign 30:abs_diff_HHmembers1} {...}
{c |}{...}
 {res}    56308  1.815905         0        14  1.606158
{txt}{ralign 30:some_shock_livestock1} {...}
{c |}{...}
 {res}    56308  .0406692         0         1  .1975244
{txt}{ralign 30:some_shock_death1} {...}
{c |}{...}
 {res}    56308   .012254         0         1  .1100186
{txt}{ralign 30:some_treated} {...}
{c |}{...}
 {res}    56308  .7596079         0         1  .4273254
{txt}{ralign 30:both_treated} {...}
{c |}{...}
 {res}    56308  .2560205         0         1  .4364371
{txt}{ralign 30:one_treated} {...}
{c |}{...}
 {res}    56308  .5035874         0         1  .4999916
{txt}{hline 31}{c BT}{hline 50}

{com}. 
. tab link_bin0 link_bin1, row
{txt}
{c TLC}{hline 16}{c TRC}
{c |} Key{col 18}{c |}
{c LT}{hline 16}{c RT}
{c |}{space 3}{it:frequency}{col 18}{c |}
{c |}{space 1}{it:row percentage}{col 18}{c |}
{c BLC}{hline 16}{c BRC}

           {c |}      1 link_bin
0 link_bin {c |}         0          1 {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}    55,140        512 {txt}{c |}{res}    55,652 
           {txt}{c |}{res}     99.08       0.92 {txt}{c |}{res}    100.00 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}       510        146 {txt}{c |}{res}       656 
           {txt}{c |}{res}     77.74      22.26 {txt}{c |}{res}    100.00 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}    55,650        658 {txt}{c |}{res}    56,308 
           {txt}{c |}{res}     98.83       1.17 {txt}{c |}{res}    100.00 

{txt}
{com}. tab link_bin0 link_bin1 if some_treated==0, row 
{txt}
{c TLC}{hline 16}{c TRC}
{c |} Key{col 18}{c |}
{c LT}{hline 16}{c RT}
{c |}{space 3}{it:frequency}{col 18}{c |}
{c |}{space 1}{it:row percentage}{col 18}{c |}
{c BLC}{hline 16}{c BRC}

           {c |}      1 link_bin
0 link_bin {c |}         0          1 {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}    13,248        106 {txt}{c |}{res}    13,354 
           {txt}{c |}{res}     99.21       0.79 {txt}{c |}{res}    100.00 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}       148         34 {txt}{c |}{res}       182 
           {txt}{c |}{res}     81.32      18.68 {txt}{c |}{res}    100.00 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}    13,396        140 {txt}{c |}{res}    13,536 
           {txt}{c |}{res}     98.97       1.03 {txt}{c |}{res}    100.00 

{txt}
{com}. tab link_bin0 link_bin1 if some_treated==1, row
{txt}
{c TLC}{hline 16}{c TRC}
{c |} Key{col 18}{c |}
{c LT}{hline 16}{c RT}
{c |}{space 3}{it:frequency}{col 18}{c |}
{c |}{space 1}{it:row percentage}{col 18}{c |}
{c BLC}{hline 16}{c BRC}

           {c |}      1 link_bin
0 link_bin {c |}         0          1 {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}    41,892        406 {txt}{c |}{res}    42,298 
           {txt}{c |}{res}     99.04       0.96 {txt}{c |}{res}    100.00 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}       362        112 {txt}{c |}{res}       474 
           {txt}{c |}{res}     76.37      23.63 {txt}{c |}{res}    100.00 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}    42,254        518 {txt}{c |}{res}    42,772 
           {txt}{c |}{res}     98.79       1.21 {txt}{c |}{res}    100.00 

{txt}
{com}. 
. /* format */
. 
. foreach var in link_s link_bin abs_diff_HHmembers abs_diff_chl16 both_married some_shock_livestock some_shock_death {c -(} 
{txt}  2{com}. gen delta_`var'= `var'1-`var'0
{txt}  3{com}. drop `var'1 `var'0
{txt}  4{com}. {c )-}
{txt}(915 missing values generated)
(915 missing values generated)

{com}. 
. /* dyadic regressions */
. 
. global controls = "delta_both_married delta_abs_diff_chl16 delta_abs_diff_HHmembers delta_some_shock_livestock delta_some_shock_death"
{txt}
{com}. 
. regress delta_link_s some_treated, noc 

{txt}      Source {c |}       SS           df       MS      Number of obs   ={res}    56,308
{txt}{hline 13}{c +}{hline 34}   F(1, 56307)     = {res}     6.28
{txt}       Model {c |} {res} .060069274         1  .060069274   {txt}Prob > F        ={res}    0.0122
{txt}    Residual {c |} {res} 538.659125    56,307  .009566468   {txt}R-squared       ={res}    0.0001
{txt}{hline 13}{c +}{hline 34}   Adj R-squared   ={res}    0.0001
{txt}       Total {c |} {res} 538.719194    56,308  .009567365   {txt}Root MSE        =   {res} .09781

{txt}{hline 13}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}delta_link_s{col 14}{c |}      Coef.{col 26}   Std. Err.{col 38}      t{col 46}   P>|t|{col 54}     [95% Con{col 67}f. Interval]
{hline 13}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
some_treated {c |}{col 14}{res}{space 2} .0011851{col 26}{space 2} .0004729{col 37}{space 1}    2.51{col 46}{space 3}0.012{col 54}{space 4} .0002581{col 67}{space 3}  .002112
{txt}{hline 13}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}{txt}
{com}. regress delta_link_s some_treated $controls

{txt}      Source {c |}       SS           df       MS      Number of obs   ={res}    56,308
{txt}{hline 13}{c +}{hline 34}   F(6, 56301)     = {res}     1.49
{txt}       Model {c |} {res} .085299139         6  .014216523   {txt}Prob > F        ={res}    0.1784
{txt}    Residual {c |} {res}  538.60825    56,301  .009566584   {txt}R-squared       ={res}    0.0002
{txt}{hline 13}{c +}{hline 34}   Adj R-squared   ={res}    0.0001
{txt}       Total {c |} {res}  538.69355    56,307   .00956708   {txt}Root MSE        =   {res} .09781

{txt}{hline 27}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}              delta_link_s{col 28}{c |}      Coef.{col 40}   Std. Err.{col 52}      t{col 60}   P>|t|{col 68}     [95% Con{col 81}f. Interval]
{hline 27}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{space 14}some_treated {c |}{col 28}{res}{space 2} .0021326{col 40}{space 2} .0009654{col 51}{space 1}    2.21{col 60}{space 3}0.027{col 68}{space 4} .0002403{col 81}{space 3} .0040248
{txt}{space 8}delta_both_married {c |}{col 28}{res}{space 2}-.0013885{col 40}{space 2} .0011686{col 51}{space 1}   -1.19{col 60}{space 3}0.235{col 68}{space 4} -.003679{col 81}{space 3}  .000902
{txt}{space 6}delta_abs_diff_chl16 {c |}{col 28}{res}{space 2} .0000288{col 40}{space 2} .0003205{col 51}{space 1}    0.09{col 60}{space 3}0.928{col 68}{space 4}-.0005993{col 81}{space 3} .0006569
{txt}{space 2}delta_abs_diff_HHmembers {c |}{col 28}{res}{space 2} .0000915{col 40}{space 2} .0002484{col 51}{space 1}    0.37{col 60}{space 3}0.713{col 68}{space 4}-.0003954{col 81}{space 3} .0005783
{txt}delta_some_shock_livestock {c |}{col 28}{res}{space 2} .0014593{col 40}{space 2} .0010101{col 51}{space 1}    1.44{col 60}{space 3}0.149{col 68}{space 4}-.0005206{col 81}{space 3} .0034392
{txt}{space 4}delta_some_shock_death {c |}{col 28}{res}{space 2}-.0013348{col 40}{space 2} .0023296{col 51}{space 1}   -0.57{col 60}{space 3}0.567{col 68}{space 4}-.0059008{col 81}{space 3} .0032312
{txt}{space 21}_cons {c |}{col 28}{res}{space 2}-.0008759{col 40}{space 2} .0008507{col 51}{space 1}   -1.03{col 60}{space 3}0.303{col 68}{space 4}-.0025433{col 81}{space 3} .0007916
{txt}{hline 27}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}{txt}
{com}. 
. matrix coeffs_dyadic=e(b)
{txt}
{com}. matrix der=coeffs_dyadic[1,1]
{txt}
{com}. 
. mata: der=st_matrix("der")
{res}{txt}
{com}. 
. /* `dyadic' command: dyadic s.e. adjusted for incomplete network data */
.    
. dyadic delta_link_s some_treated, noc id(HHNO1 HHNO2) inc



{txt}Note: there are 780002 observations missing to complete the network(s).
.

Grouped Dyadic linear regression{col 40}Number of obs{col 57}= {res}  56308
{txt}{col 40}Number of groups{col 57}= {res}      1

{col 1}{text}{hline 13}{c TT}{hline 12}{hline 14}{hline 16}{hline 9}
{col 14}{text}{c |}{col 27}    Robust
{col 1}{text}delta_link_s{col 14}{c |}      Coef.{col 27}   Std. Err.{col 41}  Gr.Dyadic s.e.{col 57}      t
{col 1}{text}{hline 13}{c +}{hline 12}{hline 14}{hline 16}{hline 9}
{col 1}{text}some_treated{col 14}{c |}{result}{space 2} .0011851{col 27}{space 2} .0004723{col 41}{space 6} .0005554{col 57}{space 1}    2.13
{col 1}{text}{hline 13}{c BT}{hline 12}{hline 14}{hline 16}{hline 9}

{com}. dyadic delta_link_s some_treated $controls, id(HHNO1 HHNO2) inc



{txt}Note: there are 780002 observations missing to complete the network(s).
.

Grouped Dyadic linear regression{col 40}Number of obs{col 57}= {res}  56308
{txt}{col 40}Number of groups{col 57}= {res}      1

{col 1}{text}{hline 13}{c TT}{hline 12}{hline 14}{hline 16}{hline 9}
{col 14}{text}{c |}{col 27}    Robust
{col 1}{text}delta_link_s{col 14}{c |}      Coef.{col 27}   Std. Err.{col 41}  Gr.Dyadic s.e.{col 57}      t
{col 1}{text}{hline 13}{c +}{hline 12}{hline 14}{hline 16}{hline 9}
{col 1}{text}some_treated{col 14}{c |}{result}{space 2} .0021326{col 27}{space 2} .0009696{col 41}{space 6} .0012806{col 57}{space 1}    1.67
{col 1}{text}delta_both~d{col 14}{c |}{result}{space 2}-.0013885{col 27}{space 2} .0009604{col 41}{space 6}  .001332{col 57}{space 1}   -1.04
{col 1}{text}delta_abs~16{col 14}{c |}{result}{space 2} .0000288{col 27}{space 2} .0003172{col 41}{space 6} .0004439{col 57}{space 1}    0.06
{col 1}{text}delta_abs_~s{col 14}{c |}{result}{space 2} .0000915{col 27}{space 2} .0002661{col 41}{space 6} .0003408{col 57}{space 1}    0.27
{col 1}{text}delta_some~k{col 14}{c |}{result}{space 2} .0014593{col 27}{space 2} .0011062{col 41}{space 6} .0012318{col 57}{space 1}    1.18
{col 1}{text}delta_some~h{col 14}{c |}{result}{space 2}-.0013348{col 27}{space 2} .0018823{col 41}{space 6}  .001851{col 57}{space 1}   -0.72
{col 1}{text}    __000000{col 14}{c |}{result}{space 2}-.0008759{col 27}{space 2} .0008464{col 41}{space 6} .0011355{col 57}{space 1}   -0.77
{col 1}{text}{hline 13}{c BT}{hline 12}{hline 14}{hline 16}{hline 9}

{com}. 
. /*******************************************************************
> ********************************************************************
>  PEER EFFECT REGRESSIONS:
>  - the dependent variable is meat consumption
>  - semi row-standardized interaction matrix 
>  - 2nd and 3rd order IVs 
>  - clustered boostrapped s.e.
> *******************************************************************
> *******************************************************************/
. 
. *******************************************************************
. * COMPUTE THE RELEVANT MATRICES
. *******************************************************************
. 
. use individual_dataset_ComolaPrina.dta, clear
{txt}
{com}. 
. mata
{txt}{hline 49} mata (type {cmd:end} to exit) {hline}
{com}: 
: /* save individual characteristics */
: 
: ITT= st_data(., "ITT")
{res}
{com}: y0= st_data(., "y0")
{res}
{com}: y1= st_data(., "y1")
{res}
{com}: 
: /* vectors of interest */
: 
: G0_ITT=G0*ITT
{res}
{com}: G0_y0=G0*y0
{res}
{com}: G0_y1=G0*y1
{res}
{com}: G0_deltay=G0*(y1-y0)
{res}
{com}: deltaG_ITT=deltaG*ITT
{res}
{com}: deltaG_y1=deltaG*y1
{res}
{com}: 
: /* IVs of second order */
: 
: IV_1=G0*G0*ITT
{res}
{com}: IV_2=deltaG*deltaG*ITT
{res}
{com}: IV_3=G0*deltaG*ITT
{res}
{com}: IV_4=deltaG*G0*ITT
{res}
{com}: 
: /* IVs of third order */
: 
: IV_5=G0*G0*G0*ITT
{res}
{com}: IV_6=deltaG*deltaG*deltaG*ITT
{res}
{com}: IV_7=G0*G0*deltaG*ITT
{res}
{com}: IV_8=deltaG*deltaG*G0*ITT
{res}
{com}: IV_9=G0*deltaG*deltaG*ITT
{res}
{com}: IV_10=deltaG*G0*G0*ITT
{res}
{com}: IV_11=G0*deltaG*G0*ITT
{res}
{com}: IV_12=deltaG*G0*deltaG*ITT
{res}
{com}: 
: results=(G0_ITT, G0_y0, G0_y1, G0_deltay, deltaG_ITT, deltaG_y1, IV_1, IV_2, IV_3, IV_4, IV_5, IV_6, IV_7, IV_8, IV_9, IV_10, IV_11, IV_12)
{res}
{com}: 
: st_matrix("result", results)
{res}
{com}: 
: end
{txt}{hline}

{com}. 
. /*re-import into Stata*/
. 
. svmat result
{txt}
{com}. 
. ren result1 G0_ITT
{res}{txt}
{com}. ren result2 G0_y0
{res}{txt}
{com}. ren result3 G0_y1
{res}{txt}
{com}. ren result4 G0_deltay
{res}{txt}
{com}. ren result5 deltaG_ITT
{res}{txt}
{com}. ren result6 deltaG_y1
{res}{txt}
{com}. ren result7 IV_1
{res}{txt}
{com}. ren result8 IV_2
{res}{txt}
{com}. ren result9 IV_3 
{res}{txt}
{com}. ren result10 IV_4 
{res}{txt}
{com}. ren result11 IV_5 
{res}{txt}
{com}. ren result12 IV_6 
{res}{txt}
{com}. ren result13 IV_7 
{res}{txt}
{com}. ren result14 IV_8 
{res}{txt}
{com}. ren result15 IV_9 
{res}{txt}
{com}. ren result16 IV_10 
{res}{txt}
{com}. ren result17 IV_11
{res}{txt}
{com}. ren result18 IV_12
{res}{txt}
{com}. 
. /* village size */
. 
. preserve
{txt}
{com}. 
. bysort village_code: gen village_tot=_N
{txt}
{com}. bysort village_code: gen serial=_n
{txt}
{com}. drop if serial>1
{txt}(896 observations deleted)

{com}. sort HHNO
{txt}
{com}. keep village_tot
{txt}
{com}. 
. mata
{txt}{hline 49} mata (type {cmd:end} to exit) {hline}
{com}: SIZE= st_data(., "village_tot")
{res}
{com}: end 
{txt}{hline}

{com}. 
. restore
{txt}
{com}. 
. *******************************************************************************
. * PEER EFFECT REGRESSIONS 
. *******************************************************************************
. 
. cap erase results_pe.txt
{txt}
{com}. cap erase results_pe.xml
{txt}
{com}. 
. set seed 07031979
{txt}
{com}. 
. /* no PE*/ 
. 
. regress delta_y ITT, nocons vce (boot, r(100) cluster(village_code))
{txt}(running regress on estimation sample)

Bootstrap replications ({res}100{txt})
{hline 4}{c +}{hline 3} 1 {hline 3}{c +}{hline 3} 2 {hline 3}{c +}{hline 3} 3 {hline 3}{c +}{hline 3} 4 {hline 3}{c +}{hline 3} 5 
..................................................    50
..................................................   100
{res}
{txt}Linear regression{col 49}Number of obs{col 67}= {res}       915
{txt}{col 49}Replications{col 67}= {res}       100
{txt}{col 49}Wald chi2({res}1{txt}){col 67}= {res}     36.19
{txt}{col 49}Prob > chi2{col 67}= {res}    0.0000
{txt}{col 49}R-squared{col 67}= {res}    0.0492
{txt}{col 49}Adj R-squared{col 67}= {res}    0.0482
{txt}{col 49}Root MSE{col 67}= {res} 1540.1588

{txt}{ralign 78:(Replications based on {res:19} clusters in village_code)}
{hline 13}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 14}{c |}   Observed{col 26}   Bootstrap{col 54}         Norm{col 67}al-based
{col 1}     delta_y{col 14}{c |}      Coef.{col 26}   Std. Err.{col 38}      z{col 46}   P>|z|{col 54}     [95% Con{col 67}f. Interval]
{hline 13}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{space 9}ITT {c |}{col 14}{res}{space 2} 489.7265{col 26}{space 2}  81.4064{col 37}{space 1}    6.02{col 46}{space 3}0.000{col 54}{space 4} 330.1729{col 67}{space 3} 649.2801
{txt}{hline 13}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}

{com}. outreg2 using results_pe, excel replace dec(2) ctitle(no PE)
{txt}{browse `"results_pe.xml"'}
{browse `"C:\Users\m.comola\Dropbox\Nepal Banking Networks\drafts\REStat submission\5. accepted\data"' :dir}{com} : {txt}{stata `"seeout using "results_pe.txt""':seeout}

{com}. 
. /* standard PE, IV */
. 
. ivregress 2sls delta_y ITT (G0_deltay = IV_1-IV_12) G0_ITT, nocons vce (boot, r(100) cluster(village_code))
{txt}(running ivregress on estimation sample)

Bootstrap replications ({res}100{txt})
{hline 4}{c +}{hline 3} 1 {hline 3}{c +}{hline 3} 2 {hline 3}{c +}{hline 3} 3 {hline 3}{c +}{hline 3} 4 {hline 3}{c +}{hline 3} 5 
..................................................    50
..................................................   100
{res}
{txt}{col 1}Instrumental variables (2SLS) regression{col 51}Number of obs{col 67}= {res}       915
{txt}{col 1}{col 51}Wald chi2({res}3{txt}){col 67}= {res}     29.76
{txt}{col 1}{col 51}Prob > chi2{col 67}= {res}    0.0000
{txt}{col 1}{col 51}R-squared{col 67}= {res}         .
{txt}{col 51}Root MSE{col 67}=    {res} 1532.2

{txt}{ralign 78:(Replications based on {res:19} clusters in village_code)}
{hline 13}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 14}{c |}   Observed{col 26}   Bootstrap{col 54}         Norm{col 67}al-based
{col 1}     delta_y{col 14}{c |}      Coef.{col 26}   Std. Err.{col 38}      z{col 46}   P>|z|{col 54}     [95% Con{col 67}f. Interval]
{hline 13}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{space 3}G0_deltay {c |}{col 14}{res}{space 2} .3876136{col 26}{space 2} .4339729{col 37}{space 1}    0.89{col 46}{space 3}0.372{col 54}{space 4}-.4629576{col 67}{space 3} 1.238185
{txt}{space 9}ITT {c |}{col 14}{res}{space 2} 399.0479{col 26}{space 2} 83.91582{col 37}{space 1}    4.76{col 46}{space 3}0.000{col 54}{space 4} 234.5759{col 67}{space 3} 563.5199
{txt}{space 6}G0_ITT {c |}{col 14}{res}{space 2} 4.408154{col 26}{space 2} 252.3142{col 37}{space 1}    0.02{col 46}{space 3}0.986{col 54}{space 4}-490.1186{col 67}{space 3} 498.9349
{txt}{hline 13}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{p 0 15 32}Instrumented:{space 2}G0_deltay{p_end}
{p 0 15 32}Instruments:{space 3}ITT G0_ITT IV_1 IV_2 IV_3 IV_4 IV_5 IV_6 IV_7 IV_8 IV_9 IV_10 IV_11 IV_12{p_end}

{com}. outreg2 using results_pe, excel append dec(2) ctitle("st PE, IV")
{txt}{browse `"results_pe.xml"'}
{browse `"C:\Users\m.comola\Dropbox\Nepal Banking Networks\drafts\REStat submission\5. accepted\data"' :dir}{com} : {txt}{stata `"seeout using "results_pe.txt""':seeout}

{com}. 
. matrix coeffs_stat=e(b)
{txt}
{com}. matrix beta1_stat= coeffs_stat[1,1]
{txt}
{com}. matrix gamma_stat= coeffs_stat[1,2]
{txt}
{com}. matrix delta1_stat= coeffs_stat[1,3]
{txt}
{com}. 
. mata: beta1_stat=st_matrix("beta1_stat")
{res}{txt}
{com}. mata: gamma_stat=st_matrix("gamma_stat")
{res}{txt}
{com}. mata: delta1_stat=st_matrix("delta1_stat")
{res}{txt}
{com}. 
. /* dynamic PE, IV*/
. 
. ivregress 2sls delta_y ITT (G0_deltay deltaG_y1 = IV_1-IV_12) G0_ITT deltaG_ITT, nocons vce (boot, r(100) cluster(village_code))
{txt}(running ivregress on estimation sample)

Bootstrap replications ({res}100{txt})
{hline 4}{c +}{hline 3} 1 {hline 3}{c +}{hline 3} 2 {hline 3}{c +}{hline 3} 3 {hline 3}{c +}{hline 3} 4 {hline 3}{c +}{hline 3} 5 
..................................................    50
..................................................   100
{res}
{txt}{col 1}Instrumental variables (2SLS) regression{col 51}Number of obs{col 67}= {res}       915
{txt}{col 1}{col 51}Wald chi2({res}5{txt}){col 67}= {res}     70.21
{txt}{col 1}{col 51}Prob > chi2{col 67}= {res}    0.0000
{txt}{col 1}{col 51}R-squared{col 67}= {res}         .
{txt}{col 51}Root MSE{col 67}=    {res} 1575.5

{txt}{ralign 78:(Replications based on {res:19} clusters in village_code)}
{hline 13}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 14}{c |}   Observed{col 26}   Bootstrap{col 54}         Norm{col 67}al-based
{col 1}     delta_y{col 14}{c |}      Coef.{col 26}   Std. Err.{col 38}      z{col 46}   P>|z|{col 54}     [95% Con{col 67}f. Interval]
{hline 13}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{space 3}G0_deltay {c |}{col 14}{res}{space 2} .7902358{col 26}{space 2} .3615744{col 37}{space 1}    2.19{col 46}{space 3}0.029{col 54}{space 4}  .081563{col 67}{space 3} 1.498909
{txt}{space 3}deltaG_y1 {c |}{col 14}{res}{space 2} .2652416{col 26}{space 2} .1139413{col 37}{space 1}    2.33{col 46}{space 3}0.020{col 54}{space 4} .0419207{col 67}{space 3} .4885624
{txt}{space 9}ITT {c |}{col 14}{res}{space 2} 281.7911{col 26}{space 2} 86.06236{col 37}{space 1}    3.27{col 46}{space 3}0.001{col 54}{space 4}  113.112{col 67}{space 3} 450.4702
{txt}{space 6}G0_ITT {c |}{col 14}{res}{space 2}-24.48625{col 26}{space 2} 247.3889{col 37}{space 1}   -0.10{col 46}{space 3}0.921{col 54}{space 4}-509.3597{col 67}{space 3} 460.3872
{txt}{space 2}deltaG_ITT {c |}{col 14}{res}{space 2}-4.704262{col 26}{space 2} 206.0819{col 37}{space 1}   -0.02{col 46}{space 3}0.982{col 54}{space 4}-408.6174{col 67}{space 3} 399.2089
{txt}{hline 13}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{p 0 15 32}Instrumented:{space 2}G0_deltay deltaG_y1{p_end}
{p 0 15 32}Instruments:{space 3}ITT G0_ITT deltaG_ITT IV_1 IV_2 IV_3 IV_4 IV_5 IV_6 IV_7 IV_8 IV_9 IV_10 IV_11 IV_12{p_end}

{com}. outreg2 using results_pe, excel append dec(2) ctitle("dyn PE, IV")
{txt}{browse `"results_pe.xml"'}
{browse `"C:\Users\m.comola\Dropbox\Nepal Banking Networks\drafts\REStat submission\5. accepted\data"' :dir}{com} : {txt}{stata `"seeout using "results_pe.txt""':seeout}

{com}. 
. matrix coeffs_dyn=e(b)
{txt}
{com}. matrix  beta1_dyn= coeffs_dyn[1,1]
{txt}
{com}. matrix  beta2_dyn= coeffs_dyn[1,2]
{txt}
{com}. matrix gamma_dyn= coeffs_dyn[1,3]
{txt}
{com}. matrix  delta1_dyn= coeffs_dyn[1,4]
{txt}
{com}. matrix  delta2_dyn= coeffs_dyn[1,5]
{txt}
{com}. 
. mata: beta1_dyn=st_matrix("beta1_dyn")
{res}{txt}
{com}. mata: beta2_dyn=st_matrix("beta2_dyn")
{res}{txt}
{com}. mata: gamma_dyn=st_matrix("gamma_dyn")
{res}{txt}
{com}. mata: delta1_dyn=st_matrix("delta1_dyn")
{res}{txt}
{com}. mata: delta2_dyn=st_matrix("delta2_dyn")
{res}{txt}
{com}. 
. test G0_deltay=deltaG_y1

{p 0 7}{space 1}{text:( 1)}{space 1} {res}G0_deltay - deltaG_y1 = 0{p_end}

{txt}{col 12}chi2(  1) ={res}    2.36
{txt}{col 10}Prob > chi2 =  {res}  0.1248
{txt}
{com}. cap erase results_pe.txt
{txt}
{com}. 
. ********************************************************************
. ********************************************************************
. *** DISTRIBUTION OF INDIVIDUAL EFFECTS
. ********************************************************************
. ********************************************************************
. 
. /* individual panel */
. 
. preserve
{txt}
{com}. 
. keep HHNO village_code y0 G0_y0
{txt}
{com}. 
. ren y0 yh
{res}{txt}
{com}. ren G0_y0 G0h_y
{res}{txt}
{com}. 
. gen deltaGh_y=0
{txt}
{com}. gen ITTh=0
{txt}
{com}. gen G0h_ITTh=0
{txt}
{com}. gen deltaGh_ITTh=0
{txt}
{com}. 
. forvalues x=1/12 {c -(}
{txt}  2{com}. gen IV_`x'=0
{txt}  3{com}. {c )-}
{txt}
{com}. 
. gen time=0
{txt}
{com}. save temp1.dta, replace 
{txt}(note: file temp1.dta not found)
file temp1.dta saved

{com}. 
. restore 
{txt}
{com}. 
. preserve
{txt}
{com}. 
. ren y1 yh
{res}{txt}
{com}. ren G0_y1 G0h_y
{res}{txt}
{com}. ren deltaG_y1 deltaGh_y
{res}{txt}
{com}. ren ITT ITTh
{res}{txt}
{com}. ren G0_ITT G0h_ITTh
{res}{txt}
{com}. ren deltaG_ITT deltaGh_ITTh
{res}{txt}
{com}. 
. keep HHNO village_code yh G0h_y deltaGh_y ITTh G0h_ITTh deltaGh_ITTh IV_1-IV_12
{txt}
{com}. gen time=1
{txt}
{com}. 
. append using temp1.dta
{txt}{p 0 7 2}
(note: variable
ITTh was 
byte, now float to accommodate using data's values)
{p_end}

{com}. capture erase temp1.dta
{txt}
{com}. 
. xtset HHNO time
{res}{txt}{col 8}panel variable:  {res}HHNO (strongly balanced)
{txt}{col 9}time variable:  {res}{col 25}time, 0 to 1
{txt}{col 17}delta:  {res}1 unit
{txt}
{com}. 
. /* save the individual effects */
. 
. qui tab HHNO, gen (code)
{txt}
{com}. xi: qui ivregress 2sls yh ITTh (G0h_y deltaGh_y = IV_1-IV_12) G0h_ITTh deltaGh_ITTh code2-code915, nocons
{txt}
{com}. matrix miu=e(b)
{txt}
{com}. matrix miu= miu[1,5...]'
{txt}
{com}. 
. clear
{txt}
{com}. svmat miu, name(miu)
{txt}number of observations will be reset to 915
Press any key to continue, or Break to abort
{p}
number of observations (_N)  was 0,
now 915
{p_end}

{com}. replace miu1=0 in 1
{txt}(1 real change made)

{com}. 
. gen serial=_n
{txt}
{com}. sort serial
{txt}
{com}. save miu.dta, replace 
{txt}(note: file miu.dta not found)
file miu.dta saved

{com}. 
. restore
{txt}
{com}. 
. gen serial=_n
{txt}
{com}. sort serial
{txt}
{com}. merge serial using miu.dta
{txt}{p}
(note: you are using old
{bf:merge} syntax; see
{bf:{help merge:[D] merge}} for new syntax)
{p_end}

{com}. drop _merge serial
{txt}
{com}. capture erase miu.dta
{txt}
{com}. 
. ********************************************************************
. ********************************************************************
. *** TOTAL TREATMENT EFFECT
. ********************************************************************
. ********************************************************************
. 
. /******************************
> * STATIC MODEL 
> ******************************/
. 
. mata 
{txt}{hline 49} mata (type {cmd:end} to exit) {hline}
{com}: 
: /* full matrix of cross derivatives */ 
: 
: A1 = J(915, 915, . )
{res}
{com}: for (i=1; i<=915; i++) {c -(}
> e= J(915,1,0)
> e[i]=1
> A1[.,i]=(luinv(I(915)-beta1_stat*G0))*(gamma_stat*e+delta1_stat*G0*e)
> {c )-}
{res}
{com}: 
: /* direct effect */
:  
: D1 = diagonal(A1)
{res}
{com}: DIRECT_static=mean(D1)
{res}
{com}: DIRECT_static
{res}  417.9231161

{com}: 
: /* total effect */ 
: 
: C1 = colsum(A1)'
{res}
{com}: TOTAL_static=mean(C1)
{res}
{com}: TOTAL_static
{res}  512.3281886

{com}: 
: /* indirect effect */ 
: 
: S1=(C1-D1)
{res}
{com}: INDIRECT_static=mean(S1)
{res}
{com}: INDIRECT_static
{res}  94.40507249

{com}: 
: end
{txt}{hline}

{com}. 
. /************************
>  DYNAMIC MODEL, NO MIUs
> ************************/
. 
. mata 
{txt}{hline 49} mata (type {cmd:end} to exit) {hline}
{com}: 
: V1=J(60,60,der)
{res}
{com}: V2=J(26,26,der)
{res}
{com}: V3=J(74,74,der)
{res}
{com}: V4=J(82,82,der)
{res}
{com}: V5=J(28,28,der)
{res}
{com}: V6=J(119,119,der)
{res}
{com}: V7=J(26,26,der)
{res}
{com}: V8=J(47,47,der)
{res}
{com}: V9=J(38,38,der)
{res}
{com}: V10=J(48,48,der)
{res}
{com}: V11=J(25,25,der)
{res}
{com}: V12=J(12,12,der)
{res}
{com}: V13=J(51,51,der)
{res}
{com}: V14=J(36,36,der)
{res}
{com}: V15=J(74,74,der)
{res}
{com}: V16=J(33,33,der)
{res}
{com}: V17=J(61,61,der)
{res}
{com}: V18=J(11,11,der)
{res}
{com}: V19=J(64,64,der)
{res}
{com}: 
: BLOCK=blockdiag(V1,blockdiag(V2,blockdiag(V3,blockdiag(V4,blockdiag(V5,blockdiag(V6,blockdiag(V7,blockdiag(V8,blockdiag(V9,blockdiag(V10,blockdiag(V11,blockdiag(V12,blockdiag(V13,blockdiag(V14,blockdiag(V15,blockdiag(V16,blockdiag(V17,blockdiag(V18,V19))))))))))))))))))
{res}
{com}: 
: /* full matrix of cross derivatives */
: 
: A2 = J(915, 915, . )
{res}
{com}: 
: for (i=1; i<=915; i++) {c -(}
> 
> e= J(915,1,0)
> e[i]=1
> 
> /* derivative of G wrt ITT_k */
> 
> DER_G=J(915, 915, 0)
> DER_G[i,.]=BLOCK[i,.]
> DER_G[.,i]=BLOCK[.,i]
> 
> S=luinv(I(915)-beta1_dyn*G0-beta2_dyn*deltaG)
> 
> M=gamma_dyn*ITT+delta1_dyn*G0*ITT+delta2_dyn*deltaG*ITT
> 
> DER_S=S*beta2_dyn*DER_G*S
> 
> DER_M=gamma_dyn*e+delta1_dyn*G0*e+delta2_dyn*DER_G*ITT+delta2_dyn*deltaG*e
> 
> A2[.,i]=DER_S*M+S*DER_M
> 
> {c )-}
{res}
{com}: 
: /* direct effect */ 
: 
: D2 = diagonal(A2)
{res}
{com}: DIRECT_dynamic=mean(D2)
{res}
{com}: DIRECT_dynamic
{res}  342.3046508

{com}: 
: /* total effect */ 
: 
: C2 = colsum(A2)'
{res}
{com}: TOTAL_dynamic=mean(C2)
{res}
{com}: TOTAL_dynamic
{res}  603.1688349

{com}: 
: /* indirect effect */ 
: 
: S2=(C2-D2)
{res}
{com}: INDIRECT_dynamic=mean(S2)
{res}
{com}: INDIRECT_dynamic
{res}  260.864184

{com}: 
: end
{txt}{hline}

{com}.  
. /*****************************
>  DYNAMIC MODEL, ESTIMATED MIUs
> *****************************/
. 
. mata 
{txt}{hline 49} mata (type {cmd:end} to exit) {hline}
{com}: 
: miu= st_data(., " miu1")
{res}
{com}: 
: V1=J(60,60,der)
{res}
{com}: V2=J(26,26,der)
{res}
{com}: V3=J(74,74,der)
{res}
{com}: V4=J(82,82,der)
{res}
{com}: V5=J(28,28,der)
{res}
{com}: V6=J(119,119,der)
{res}
{com}: V7=J(26,26,der)
{res}
{com}: V8=J(47,47,der)
{res}
{com}: V9=J(38,38,der)
{res}
{com}: V10=J(48,48,der)
{res}
{com}: V11=J(25,25,der)
{res}
{com}: V12=J(12,12,der)
{res}
{com}: V13=J(51,51,der)
{res}
{com}: V14=J(36,36,der)
{res}
{com}: V15=J(74,74,der)
{res}
{com}: V16=J(33,33,der)
{res}
{com}: V17=J(61,61,der)
{res}
{com}: V18=J(11,11,der)
{res}
{com}: V19=J(64,64,der)
{res}
{com}: 
: BLOCK=blockdiag(V1,blockdiag(V2,blockdiag(V3,blockdiag(V4,blockdiag(V5,blockdiag(V6,blockdiag(V7,blockdiag(V8,blockdiag(V9,blockdiag(V10,blockdiag(V11,blockdiag(V12,blockdiag(V13,blockdiag(V14,blockdiag(V15,blockdiag(V16,blockdiag(V17,blockdiag(V18,V19))))))))))))))))))
{res}
{com}: 
: /* full matrix of cross derivatives */
: 
: A2 = J(915, 915, . )
{res}
{com}: 
: for (i=1; i<=915; i++) {c -(}
> 
> e= J(915,1,0)
> e[i]=1
> 
> DER_G=J(915, 915, 0)
> DER_G[i,.]=BLOCK[i,.]
> DER_G[.,i]=BLOCK[.,i]
> 
> S=luinv(I(915)-beta1_dyn*G0-beta2_dyn*deltaG)
> 
> M=gamma_dyn*ITT+delta1_dyn*G0*ITT+delta2_dyn*deltaG*ITT+miu
> 
> DER_S=S*beta2_dyn*DER_G*S
> 
> DER_M=gamma_dyn*e+delta1_dyn*G0*e+delta2_dyn*DER_G*ITT+delta2_dyn*deltaG*e
> 
> A2[.,i]=DER_S*M+S*DER_M
> 
> {c )-}
{res}
{com}: 
: /* direct effect */ 
: 
: D2 = diagonal(A2)
{res}
{com}: DIRECT_dynamic=mean(D2)
{res}
{com}: DIRECT_dynamic
{res}  370.8604671

{com}: 
: /* total effect */ 
: 
: C2 = colsum(A2)'
{res}
{com}: TOTAL_dynamic=mean(C2)
{res}
{com}: TOTAL_dynamic
{res}  700.2406208

{com}: 
: /* indirect effect */ 
: 
: S2=(C2-D2)
{res}
{com}: INDIRECT_dynamic=mean(S2)
{res}
{com}: INDIRECT_dynamic
{res}  329.3801537

{com}: 
: end
{txt}{hline}

{com}. 
. /*******************************************************************************
> CHECK FOR WEAK IDENTIFICATION (Beugnot et al. EER 2019) 
> *******************************************************************************/
. 
. mata
{txt}{hline 49} mata (type {cmd:end} to exit) {hline}
{com}: 
: M1 = I(915)
{res}
{com}: M1 = colshape(M1, 1) 
{res}
{com}: 
: M2 = G0
{res}
{com}: M2 = colshape(M2, 1) 
{res}
{com}: 
: M3 = deltaG
{res}
{com}: M3 = colshape(M3, 1) 
{res}
{com}: 
: M4 = G0*G0
{res}
{com}: M4 = colshape(M4, 1) 
{res}
{com}: 
: M5 = deltaG*deltaG
{res}
{com}: M5 = colshape(M5, 1) 
{res}
{com}: 
: M6 = G0*deltaG
{res}
{com}: M6 = colshape(M6, 1) 
{res}
{com}: 
: M7 = deltaG*G0
{res}
{com}: M7 = colshape(M7, 1) 
{res}
{com}: 
: condition_matrix=(M1, M2, M3, M4, M5, M6, M7)
{res}
{com}: condition_number=cond(condition_matrix)
{res}
{com}: 
: condition_number
{res}  6.760472698

{com}: 
: end
{txt}{hline}

{com}. 
. 
{txt}end of do-file

{com}. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\m.comola\Dropbox\Nepal Banking Networks\drafts\REStat submission\5. accepted\data\dofile ComolaPrina.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}16 Jan 2020, 09:40:50
{txt}{.-}
{smcl}
{txt}{sf}{ul off}